// Package models
package models

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"

	"git.oschina.net/baayso/gobms/core/utils"
)

var db *sql.DB

func init() {
	dbType := utils.Conf.GetValue("dbType")
	dbName := utils.Conf.GetValue("dbName")
	dbPwd := utils.Conf.GetValue("dbPwd")
	dbUrl := utils.Conf.GetValue("dbUrl")

	// root:root@tcp(127.0.0.1:3306)/gobms?charset=utf8
	dataSourceName := fmt.Sprintf("%s:%s@%s", dbName, dbPwd, dbUrl)

	var err error
	db, err = sql.Open(dbType, dataSourceName)
	if err != nil {
		log.Fatalf("Fail: %v\n", err)
	}

	// defer db.Close()
}
